package com.redhat.redwork.widget.select;

import java.util.Map;

import com.opensymphony.xwork2.ActionSupport;

/**
 * will be replace dropdown component
 * @author Justin
 *
 */
public class SelectAction extends ActionSupport {

	private static final long serialVersionUID = -8438569167069319583L;
	
	private SelectApplication selectApplication;
	
	protected Map<Object,Object> data;
	/** the selected value of master dropdown */
	protected String parentValue;
	
	/** data model name define in component */
	protected String model;

	@Override
	public String execute() throws Exception {
		try{
			data = loadData();
			return SUCCESS;
		}catch(Throwable t){
			return ERROR;
		}
	}
	
	/**
	 * 
	 * @return
	 */
	protected Map<Object,Object> loadData(){
		SelectModel selectModel = selectApplication.findModel(model);
		return selectModel.loadData(parentValue);
	}
	
	public void setSelectApplication(SelectApplication selectApplication) {
		this.selectApplication = selectApplication;
	}

	public Map<Object, Object> getData() {
		return data;
	}

	public void setModel(String model) {
		this.model = model;
	}

	public void setParentValue(String parentValue) {
		this.parentValue = parentValue;
	}
}
